package com.lagou.web;

import com.lagou.dao.StudentDao;
import com.lagou.domain.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Administrator
 */
public class EditStudent extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("edit...."+req.getParameter("id"));
        String idStr = req.getParameter("id");
        if(req.getParameter("id") instanceof String){
            System.out.println("---------string-------");
        }

        if(idStr == null || idStr.isEmpty()){
            System.out.println("请输入id");
            return;
        }

        int id = Integer.parseInt(req.getParameter("id"));
        System.out.println("id = " + id);
        Student student = new StudentDao().get(id);
        req.setAttribute("student",student);
        System.out.println(student.toString());
        //转发
        req.getRequestDispatcher("/editStudent.jsp").forward(req, resp);
    }
}
